package se.sics.drsm.util;

import java.util.List;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CollectionUtil {

    private static Random randomGenerator = new Random();
    private static Logger logger = LoggerFactory.getLogger(CollectionUtil.class);

    public static <T> T getRandomElem(List<T> list) {
        int randomIndex = 0;

        if (list != null)
            randomIndex = randomGenerator.nextInt(list.size());

        return list.get(randomIndex);
    }

    public static <T> T getFirstElem(List<T> list) {
        if (list == null || list.size() <= 0) {
            logger.warn("Null or empty list received.");
            return null;
        }


        return list.get(0);
    }

}
